#coding:utf-8
"""Copyright (c) 2022 God Forever
Online-class Efficiency Optimizer is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details."""
from multiprocessing import Process,Queue
import psutil
import os
import time
from tkinter.messagebox import *
import win32api
from win32process import *
import keyboard
from win32gui import *
import sys
dddddd=0
def getFileDescription(windows_exe):
    try:
        language, codepage = win32api.GetFileVersionInfo(windows_exe, '\\VarFileInfo\\Translation')[0]
        stringFileInfo = u'\\StringFileInfo\\%04X%04X\\%s' % (language, codepage, "FileDescription")
        description = win32api.GetFileVersionInfo(windows_exe, stringFileInfo)
    except:
        description = "unknown"
    return description
def Name(i):
    try:
        return (getFileDescription(i.exe()))
    except:
        return ("unknown")
while True:
    aa = open("locker.txt", "a")
    aa.close()
    try:
        aa = open("locker.txt", "r")
        bbb2 = aa.readlines()
    except:
        aa = open("locker.txt", "r", encoding="utf-8")
        bbb2 = aa.readlines()
    for i in range(len(bbb2)):
        bbb2[i] = bbb2[i].replace("\n", "")
    while True:
        try:
            bbb2.remove("")
        except:
            break
    aa.close()
    ak=bbb2
    try:
        handle = GetForegroundWindow()
        try:
            name=GetWindowText(handle)
            ccc=not (dddddd==1 and name=="提示")
        except:
            ccc=False
        pid = GetWindowThreadProcessId(handle)[-1]
        i = psutil.Process(pid)
        a=False
        for j in ak:
            if i.name().lower() == j.lower() or i.name()[:i.name().find(".")].lower() == j.lower() or j.lower() == str(Name(i)).lower():
                a=True
        if a:
            if dddddd==0:
                dddddd=1
            for i in range(150):
                if not i in [83, 42, 54, 29, 56]:
                    keyboard.block_key(i)
        else:
            if ccc:
                if dddddd==1:
                    dddddd=0
                keyboard.unhook_all()
    except:
        if False:
            print()
    time.sleep(0.5)